package com.jrwd.recycletest;

import android.app.Activity;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

/**
 * Created by ${templefck} on 2018/8/1.
 */
public class ShareUtils {


    private Activity activity;

    private UMShareListener umShareListener;


    public ShareUtils(final Activity activity){
        this.activity = activity;
        umShareListener = new UMShareListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {

            }

            @Override
            public void onResult(SHARE_MEDIA share_media) {
                Toast.makeText(activity,"分享成功", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                Toast.makeText(activity,"分享失败", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media) {
                Toast.makeText(activity,"分享取消", Toast.LENGTH_SHORT).show();
            }
        };
    }
    /**
     * 分类链接
     * @param url    链接
     */
    public void shareUrl(String url){
        UMWeb umWeb = new UMWeb(url);
        umWeb.setTitle("测试 ");//标题
        umWeb.setThumb(new UMImage(activity, R.drawable.umeng_socialize_delete));  //缩略图
        umWeb.setDescription("我的天哪");//描述

        new ShareAction(activity)
                .setDisplayList( SHARE_MEDIA.QQ,SHARE_MEDIA.SINA,SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .withMedia(umWeb)
                .setCallback(umShareListener)
                .open();
    }
}
